package com.store.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.CommissionMemberBean;

import java.util.List;

/**
 * 会员列表的adapter .
 * Created by Liam on 2018/4/2.
 */

public class CommissionMembersAdapter extends BaseAdapter {

    private Context context;
    private List<CommissionMemberBean> list;

    public CommissionMembersAdapter(Context context, List<CommissionMemberBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_commission_member, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CommissionMemberBean bean = list.get(position);
        holder.mobile.setText(bean.getMobile());
        holder.cash.setText(String.valueOf(bean.getCash_balance()));
        holder.gold.setText(String.valueOf(bean.getGold()));

        return convertView;
    }

    public static class ViewHolder {
        public TextView mobile;
        public TextView cash;
        public TextView gold;

        public ViewHolder(View rootView) {
            this.mobile = (TextView) rootView.findViewById(R.id.tv_commission_member_mobile);
            this.cash = (TextView) rootView.findViewById(R.id.tv_commission_member_cash);
            this.gold = (TextView) rootView.findViewById(R.id.tv_commission_member_gold);
        }
    }

}
